import 'package:boss/provider/store_message_provider.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:boss/ui/widget/picker/imagePicker/image_picker.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';

class Avatar extends StatelessWidget {
  final String image;
  final double size;

  const Avatar({
    Key key,
    @required this.image,
    @required this.size,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () async {
        var image = await ImagePicker.pickImage(context);
        if (image != null) {
          var url = await UploadUtil.uploadImage(image);
          if (url != null) {
            var storeMessageProvider = Provider.of<StoreMessageProvider>(context, listen: false);
            storeMessageProvider.updateStoreHeadImage(url);
          }
        }
      },
      child: BaseImage(
        image,
        width: size,
        height: size,
        borderRadius: BorderRadius.circular(size),
      ),
    );
  }
}
